package com.ssy.lingxi.report.handler.init;

import cn.hutool.core.date.DateUtil;
import com.ssy.lingxi.report.constant.Constants;
import com.ssy.lingxi.report.service.IActiveMerchantService;
import com.ssy.lingxi.report.service.IPopularShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.annotation.Order;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

@Component
@Order(value = 10)
public class DataInitHandler implements ApplicationRunner {

    @Autowired
    private IActiveMerchantService activeMerchantService;

    @Autowired
    private IPopularShopService popularShopService;

    @Async
    @Override
    public void run(ApplicationArguments args) throws Exception {

    }

    /**
     * 活跃商户
     */
    private void activeMerchantTask() {
        // 查询前30天数据
        Long startTime = DateUtil.offsetDay(DateUtil.date(), -31).getTime();
        // 查询top10
        Integer count = 10;
        activeMerchantService.ActiveMerchantTask(startTime, count);
    }

    /**
     * 人气店铺
     */
    private void popularShopTask() {
        // 查询前7天数据
        Long startTime = DateUtil.offsetDay(DateUtil.date(), -8).getTime();
        popularShopService.popularShopTask(startTime, Constants.STATISTICS_POPULAR_SHOP_COUNT);
    }
}

